<template>
  <div>
    <h1>{{ this.arr.filter((item) => item.done === false).length }}</h1>
    <hr />
    <h1>{{ num }}</h1>
    <hr />
    <input type="checkbox" v-model="all" />:全选
    <ul>
      <li v-for="item in arr" :key="item.id">
        <input type="checkbox" v-model="item.done" />{{ item.name }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      arr: [
        { id: 1, name: "吃饭", done: true },
        { id: 2, name: "睡觉", done: false },
        { id: 3, name: "打豆豆", done: false },
      ],
    };
  },
  computed: {
    num() {
      return this.arr.filter((item) => item.done === false).length;
    },
    all: {
      get() {
        return this.arr.every((item) => item.done);
      },
      set(value) {
        this.arr.forEach((item) => (item.done = value));
      },
    },
  },
  watch: {},
  created() {},
  methods: {},
};
</script>

<style scoped></style>
